﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BesAsm.Framework.CommonControls
{
  /// <summary>
  /// A simple property form for displaying and editing properties of an object
  /// </summary>
  public partial class PropertyWindow : Form
  {

    public PropertyWindow()
    {
      InitializeComponent();
    }
    public PropertyWindow(object propertyObject, string title)
      : this()
    {
      this.propertyGrid1.SelectedObject = propertyObject;
      this.Text = title;
    }

    public object PropertyObject
    {
      get { return this.propertyGrid1.SelectedObject; }
      set { this.propertyGrid1.SelectedObject = value; }
    }

    public PropertyGrid PropertyGrid
    {
      get { return this.propertyGrid1; }
    }

    public string Title
    {
      get { return this.Text; }
      set { this.Text = value; }
    }

    public void Show()
    {
      if (this.propertyGrid1.SelectedObject == null)
        throw new Exception("No property object set");
      base.Show();
    }

    public void Show(object o)
    {
      propertyGrid1.SelectedObject = o;
      base.Show();
    }

    private void PropertyWindow_FormClosing(object sender, FormClosingEventArgs e)
    {
      if (e.CloseReason == CloseReason.UserClosing)
      {
        Hide();
        e.Cancel = true;
      }
    }



  }
}
